package com.lb.shopguide.im.session.Action;

import com.lb.shopguide.R;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.goods.GoodsInChatBean;
import com.lb.shopguide.entity.goods.GoodsInListBean;
import com.lb.shopguide.im.callback.GoodsCallback;
import com.lb.shopguide.im.session.extension.GoodsAttachment;
import com.lb.shopguide.ui.activity.MessageDetailChooseActivity;
import com.netease.nim.uikit.business.session.actions.BaseAction;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.model.IMMessage;

import java.util.List;

/**
 * Created by kang on 2017/6/6.
 */

public class GoodsAction extends BaseAction {
    private String accId = "";

    public GoodsAction() {
        super(R.drawable.iv_message_goods, R.string.input_panel_goods);
    }

    public GoodsAction(String accId) {
        super(R.drawable.iv_message_goods, R.string.input_panel_goods);
        this.accId = accId;
    }

    @Override
    public void onClick() {
        MessageDetailChooseActivity.start(getActivity(), new GoodsCallback() {
            @Override
            public void onGoodsSelected(List<GoodsInListBean> list) {
                for (GoodsInListBean bean : list) {
                    GoodsInChatBean chatBean = new GoodsInChatBean();
                    chatBean = chatBean.getChatBean(bean);
                    GoodsAttachment goodsAttachment = new GoodsAttachment(chatBean);
                    IMMessage message = MessageBuilder.createCustomMessage(getAccount(), getSessionType(), "商品", goodsAttachment);
                    sendMessage(message);
                }
            }
        }, accId, AppConstant.CONSTANT_MESSAGE_CHOOSE_GOODS);
    }
}
